﻿$(document).ready(function () {
    var url = new cloudninja.metering.services.UrlBuilder()
                .forEntity("TotalResourceUsage")
                .query(cloudninja.metering.services.Settings.serviceUrlPath)
                .withMonth(month)
                .withYear(year)
                .orderBy("TenantId desc")
                .build();

    cloudninja.metering.services.GenericService.loadArrayResult(url, function (result, data) {
        for (var i = 0; i < data.length; i++) {
            $("#tenantList").dataTable().fnAddData([
                            data[i].TenantId,
                            data[i].TotalDbs,
                            data[i].TotalStg,
                            data[i].TotalBwe,
                            data[i].TWU]);
        }
    });

    $.template("tenantColumnTemplate", $('#tenantColumnTemplate'));

    $("#tenantList").dataTable({
        bLengthChange: false,
        bFilter: false,
        iDisplayLength: 20,
        aoColumnDefs: [
                    {
                        aTargets: [0],
                        fnRender: function (oObj, sVal) {
                            return $("#tenantColumnTemplate").tmpl({
                                TenantId: sVal,
                                Year: year,
                                Month: month
                            }).html();
                        },
                        bUseRendered: false
                    }
                ]
    });
});
